﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.RequestFactory
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;

namespace Microsoft.InfoCards
{
    internal class RequestFactory
    {
        private static readonly RequestFactory.RequestName[] s_uiClientRequests = new RequestFactory.RequestName[4]
    {
      RequestFactory.RequestName.GetBrowserTokenRequest,
      RequestFactory.RequestName.GetTokenRequest,
      RequestFactory.RequestName.ImportRequest,
      RequestFactory.RequestName.ManageRequest
    };
        private static object s_createRequestSync = new object();
        private static Dictionary<string, RequestFactory.RequestName> s_requestMap = new Dictionary<string, RequestFactory.RequestName>(54);
        private const int MaxRequestBlobSize = 20971520;

        private RequestFactory()
        {
        }

        static RequestFactory()
        {
            RequestFactory.s_requestMap["CloseCryptoHandleRequest"] = RequestFactory.RequestName.CloseCryptoHandleRequest;
            RequestFactory.s_requestMap["DecryptRequest"] = RequestFactory.RequestName.DecryptRequest;
            RequestFactory.s_requestMap["EncryptRequest"] = RequestFactory.RequestName.EncryptRequest;
            RequestFactory.s_requestMap["GenerateDerivedKeyRequest"] = RequestFactory.RequestName.GenerateDerivedKeyRequest;
            RequestFactory.s_requestMap["GetBrowserTokenRequest"] = RequestFactory.RequestName.GetBrowserTokenRequest;
            RequestFactory.s_requestMap["GetCryptoTransformRequest"] = RequestFactory.RequestName.GetCryptoTransformRequest;
            RequestFactory.s_requestMap["GetKeyedHashRequest"] = RequestFactory.RequestName.GetKeyedHashRequest;
            RequestFactory.s_requestMap["GetTokenRequest"] = RequestFactory.RequestName.GetTokenRequest;
            RequestFactory.s_requestMap["HashCoreRequest"] = RequestFactory.RequestName.HashCoreRequest;
            RequestFactory.s_requestMap["HashFinalRequest"] = RequestFactory.RequestName.HashFinalRequest;
            RequestFactory.s_requestMap["ImportRequest"] = RequestFactory.RequestName.ImportRequest;
            RequestFactory.s_requestMap["ManageRequest"] = RequestFactory.RequestName.ManageRequest;
            RequestFactory.s_requestMap["SignHashRequest"] = RequestFactory.RequestName.SignHashRequest;
            RequestFactory.s_requestMap["TransformBlockRequest"] = RequestFactory.RequestName.TransformBlockRequest;
            RequestFactory.s_requestMap["TransformFinalBlockRequest"] = RequestFactory.RequestName.TransformFinalBlockRequest;
            RequestFactory.s_requestMap["VerifyHashRequest"] = RequestFactory.RequestName.VerifyHashRequest;
            RequestFactory.s_requestMap["BeginCreateSecurityTokenRequest"] = RequestFactory.RequestName.BeginCreateSecurityTokenRequest;
            RequestFactory.s_requestMap["BeginSelectCardRequest"] = RequestFactory.RequestName.BeginSelectCardRequest;
            RequestFactory.s_requestMap["CancelAsyncOperationRequest"] = RequestFactory.RequestName.CancelAsyncOperationRequest;
            RequestFactory.s_requestMap["CheckStoreFileValidityRequest"] = RequestFactory.RequestName.CheckStoreFileValidityRequest;
            RequestFactory.s_requestMap["CreateCardRequest"] = RequestFactory.RequestName.CreateCardRequest;
            RequestFactory.s_requestMap["DeleteCardRequest"] = RequestFactory.RequestName.DeleteCardRequest;
            RequestFactory.s_requestMap["DeleteStoreRequest"] = RequestFactory.RequestName.DeleteStoreRequest;
            RequestFactory.s_requestMap["EndCreateSecurityTokenRequest"] = RequestFactory.RequestName.EndCreateSecurityTokenRequest;
            RequestFactory.s_requestMap["EndSelectCardRequest"] = RequestFactory.RequestName.EndSelectCardRequest;
            RequestFactory.s_requestMap["ExportFileRequest"] = RequestFactory.RequestName.ExportFileRequest;
            RequestFactory.s_requestMap["GetCertificateRequest"] = RequestFactory.RequestName.GetCertificateRequest;
            RequestFactory.s_requestMap["GetImportedCardRequest"] = RequestFactory.RequestName.GetImportedCardRequest;
            RequestFactory.s_requestMap["GetImportFileNameRequest"] = RequestFactory.RequestName.GetImportFileNameRequest;
            RequestFactory.s_requestMap["GetLedgerEntryForRecipientRequest"] = RequestFactory.RequestName.GetLedgerEntryForRecipientRequest;
            RequestFactory.s_requestMap["GetLedgerRequest"] = RequestFactory.RequestName.GetLedgerRequest;
            RequestFactory.s_requestMap["GetPolicyDetailsRequest"] = RequestFactory.RequestName.GetPolicyDetailsRequest;
            RequestFactory.s_requestMap["GetRecipientListRequest"] = RequestFactory.RequestName.GetRecipientListRequest;
            RequestFactory.s_requestMap["GetRecipientRequest"] = RequestFactory.RequestName.GetRecipientRequest;
            RequestFactory.s_requestMap["GetUserPreferenceRequest"] = RequestFactory.RequestName.GetUserPreferenceRequest;
            RequestFactory.s_requestMap["ImportFileRequest"] = RequestFactory.RequestName.ImportFileRequest;
            RequestFactory.s_requestMap["InfoCardListRequest"] = RequestFactory.RequestName.InfoCardListRequest;
            RequestFactory.s_requestMap["ListCardsInFileRequest"] = RequestFactory.RequestName.ListCardsInFileRequest;
            RequestFactory.s_requestMap["QueryStoreStatusRequest"] = RequestFactory.RequestName.QueryStoreStatusRequest;
            RequestFactory.s_requestMap["ResolvePPIDRequest"] = RequestFactory.RequestName.ResolvePPIDRequest;
            RequestFactory.s_requestMap["SaveCardRequest"] = RequestFactory.RequestName.SaveCardRequest;
            RequestFactory.s_requestMap["SaveLedgerEntryRequest"] = RequestFactory.RequestName.SaveLedgerEntryRequest;
            RequestFactory.s_requestMap["SaveRecipientRequest"] = RequestFactory.RequestName.SaveRecipientRequest;
            RequestFactory.s_requestMap["SendAgentStatusRequest"] = RequestFactory.RequestName.SendAgentStatusRequest;
            RequestFactory.s_requestMap["SetUserPreferenceRequest"] = RequestFactory.RequestName.SetUserPreferenceRequest;
            RequestFactory.s_requestMap["BeginGetFileNameFromUserRequest"] = RequestFactory.RequestName.BeginGetFileNameFromUserRequest;
            RequestFactory.s_requestMap["EndGetFileNameFromUserRequest"] = RequestFactory.RequestName.EndGetFileNameFromUserRequest;
            RequestFactory.s_requestMap["UIEndRequest"] = RequestFactory.RequestName.UIEndRequest;
            RequestFactory.s_requestMap["ListDependantCardsRequest"] = RequestFactory.RequestName.ListDependantCardsRequest;
            RequestFactory.s_requestMap["GetLastErrorDetailsRequest"] = RequestFactory.RequestName.GetLastErrorDetailsRequest;
            RequestFactory.s_requestMap["GetIsBrowserClientRequest"] = RequestFactory.RequestName.GetIsBrowserClientRequest;
            RequestFactory.s_requestMap["SetUserLanguageRequest"] = RequestFactory.RequestName.SetUserLanguageRequest;
            RequestFactory.s_requestMap["GetCardDetailsRequest"] = RequestFactory.RequestName.GetCardDetailsRequest;
            RequestFactory.s_requestMap["UnlockCardRequest"] = RequestFactory.RequestName.UnlockCardRequest;
        }

        internal static int ProcessNewRequest(
          int parentRequestHandle,
          IntPtr rpcHandle,
          IntPtr inArgs,
          out IntPtr outArgs)
        {
            InfoCardTrace.Assert(null == WindowsIdentity.GetCurrent(true), "unexpected user context on incoming thread");
            int num = 0;
            outArgs = IntPtr.Zero;
            if (IntPtr.Zero == inArgs)
                return -1073413888;
            if (IntPtr.Zero == rpcHandle)
                return -1073413888;
            try
            {
                RpcRequest structure = (RpcRequest)Marshal.PtrToStructure(inArgs, typeof(RpcRequest));
                if (structure.Length < 0 || structure.Length > 20971520 || structure.Type == null || structure.Length > 0 && IntPtr.Zero == structure.Data)
                    return -1073413888;
                Stream inStream;
                if (structure.Length != 0)
                {
                    byte[] numArray = new byte[structure.Length];
                    Marshal.Copy(structure.Data, numArray, 0, structure.Length);
                    inStream = (Stream)new MemoryStream(numArray, 0, numArray.Length, false, false);
                }
                else
                    inStream = (Stream)new MemoryStream();
                MemoryStream outStream = new MemoryStream();
                if (parentRequestHandle == 0)
                {
                    using (UIAgentMonitorHandle monitorHandle = new UIAgentMonitorHandle())
                    {
                        using (ClientRequest clientRequestInstance = RequestFactory.CreateClientRequestInstance(monitorHandle, structure.Type, rpcHandle, inStream, (Stream)outStream))
                        {
                            string extendedMessage;
                            num = clientRequestInstance.DoProcessRequest(out extendedMessage);
                            RpcResponse outArgs1;
                            RequestFactory.ConvertStreamToIntPtr(outStream, out outArgs1);
                            outArgs = outArgs1.Marshal();
                        }
                    }
                }
                else
                {
                    ClientUIRequest requestByHandle = (ClientUIRequest)Request.FindRequestByHandle(parentRequestHandle);
                    InfoCardTrace.Assert(null != requestByHandle, "ParentRequest is null");
                    using (UIAgentRequest agentRequestInstance = RequestFactory.CreateUIAgentRequestInstance(requestByHandle, structure.Type, rpcHandle, inStream, (Stream)outStream))
                    {
                        string extendedMessage;
                        num = agentRequestInstance.DoProcessRequest(out extendedMessage);
                        if (num != 0)
                            Utility.SerializeString(new BinaryWriter((Stream)outStream, Encoding.Unicode), extendedMessage);
                        RpcResponse outArgs1;
                        RequestFactory.ConvertStreamToIntPtr(outStream, out outArgs1);
                        outArgs = outArgs1.Marshal();
                    }
                }
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException != null && ex.InnerException is InfoCardBaseException)
                    num = ((InfoCardBaseException)ex.InnerException).NativeHResult;
                else
                    InfoCardService.Crash((Exception)ex);
            }
            catch (InfoCardBaseException ex)
            {
                num = ex.NativeHResult;
            }
            catch (OutOfMemoryException ex)
            {
                num = -2147024882;
            }
            catch (EndOfStreamException ex)
            {
                num = -1073413863;
            }
            catch (Exception ex)
            {
                InfoCardTrace.TraceAndLogException(ex);
                InfoCardService.Crash(ex);
            }
            return num;
        }

        private static void ConvertStreamToIntPtr(MemoryStream outStream, out RpcResponse outArgs)
        {
            byte[] buffer = outStream.GetBuffer();
            outArgs = new RpcResponse();
            outArgs.Length = 0;
            outArgs.Data = IntPtr.Zero;
            if (buffer == null || buffer.Length == 0)
                return;
            IntPtr destination = Marshal.AllocHGlobal(buffer.Length);
            Marshal.Copy(buffer, 0, destination, buffer.Length);
            outArgs.Data = destination;
            outArgs.Length = buffer.Length;
        }

        private static ClientRequest CreateClientRequestInstance(
          UIAgentMonitorHandle monitorHandle,
          string reqName,
          IntPtr rpcHandle,
          Stream inStream,
          Stream outStream)
        {
            ClientRequest clientRequest = (ClientRequest)null;
            lock (RequestFactory.s_createRequestSync)
            {
                if (string.IsNullOrEmpty(reqName))
                    throw InfoCardTrace.ThrowHelperError((Exception)new CommunicationException());
                if (!RequestFactory.s_requestMap.ContainsKey(reqName))
                    throw InfoCardTrace.ThrowHelperError((Exception)new CommunicationException());
                RequestFactory.RequestName request = RequestFactory.s_requestMap[reqName];
                if (-1 != Array.IndexOf<RequestFactory.RequestName>(RequestFactory.s_uiClientRequests, request))
                {
                    Process contextMapping = ClientUIRequest.GetContextMapping(rpcHandle, true);
                    InfoCardTrace.ThrowInvalidArgumentConditional(null == contextMapping, nameof(rpcHandle));
                    int tSSession = 0;
                    if (!NativeMethods.ProcessIdToSessionId(contextMapping.Id, out tSSession))
                        throw InfoCardTrace.ThrowHelperError((Exception)new CommunicationException(SR.GetString("ServiceErrorGettingClientTSSession"), (Exception)new Win32Exception(Marshal.GetLastWin32Error())));
                    WindowsIdentity executionIdentity = NativeMcppMethods.CreateServiceExecutionIdentity(contextMapping);
                    InfoCardUIAgent agent = monitorHandle.CreateAgent(contextMapping.Id, executionIdentity, tSSession);
                    switch (RequestFactory.s_requestMap[reqName])
                    {
                        case RequestFactory.RequestName.GetBrowserTokenRequest:
                            clientRequest = (ClientRequest)new GetBrowserTokenRequest(contextMapping, executionIdentity, agent, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.GetTokenRequest:
                            clientRequest = (ClientRequest)new GetTokenRequest(contextMapping, executionIdentity, agent, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.ImportRequest:
                            clientRequest = (ClientRequest)new ImportRequest(contextMapping, executionIdentity, agent, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.ManageRequest:
                            clientRequest = (ClientRequest)new ManageRequest(contextMapping, executionIdentity, agent, rpcHandle, inStream, outStream);
                            break;
                        default:
                            throw InfoCardTrace.ThrowHelperError((Exception)new CommunicationException());
                    }
                }
                else
                {
                    Process processFromRpcHandle = ClientRequest.GetCallingProcessFromRpcHandle(rpcHandle);
                    WindowsIdentity executionIdentity = NativeMcppMethods.CreateServiceExecutionIdentity(processFromRpcHandle);
                    switch (RequestFactory.s_requestMap[reqName])
                    {
                        case RequestFactory.RequestName.CloseCryptoHandleRequest:
                            clientRequest = (ClientRequest)new CloseCryptoHandleRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.DecryptRequest:
                            clientRequest = (ClientRequest)new DecryptRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.EncryptRequest:
                            clientRequest = (ClientRequest)new EncryptRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.GenerateDerivedKeyRequest:
                            clientRequest = (ClientRequest)new GenerateDerivedKeyRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.GetCryptoTransformRequest:
                            clientRequest = (ClientRequest)new GetCryptoTransformRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.GetKeyedHashRequest:
                            clientRequest = (ClientRequest)new GetKeyedHashRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.HashCoreRequest:
                            clientRequest = (ClientRequest)new HashCoreRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.HashFinalRequest:
                            clientRequest = (ClientRequest)new HashFinalRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.SignHashRequest:
                            clientRequest = (ClientRequest)new SignHashRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.TransformBlockRequest:
                            clientRequest = (ClientRequest)new TransformBlockRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.TransformFinalBlockRequest:
                            clientRequest = (ClientRequest)new TransformFinalBlockRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        case RequestFactory.RequestName.VerifyHashRequest:
                            clientRequest = (ClientRequest)new VerifyHashRequest(processFromRpcHandle, executionIdentity, rpcHandle, inStream, outStream);
                            break;
                        default:
                            throw InfoCardTrace.ThrowHelperError((Exception)new CommunicationException());
                    }
                }
                clientRequest.Initialize();
            }
            return clientRequest;
        }

        private static UIAgentRequest CreateUIAgentRequestInstance(
          ClientUIRequest parentRequest,
          string reqName,
          IntPtr rpcHandle,
          Stream inStream,
          Stream outStream)
        {
            UIAgentRequest uiAgentRequest = (UIAgentRequest)null;
            lock (RequestFactory.s_createRequestSync)
            {
                InfoCardTrace.Assert(!string.IsNullOrEmpty(reqName), "Null or empty request name");
                InfoCardTrace.Assert(RequestFactory.s_requestMap.ContainsKey(reqName), "Request map does not contain " + reqName);
                switch (RequestFactory.s_requestMap[reqName])
                {
                    case RequestFactory.RequestName.BeginCreateSecurityTokenRequest:
                        uiAgentRequest = (UIAgentRequest)new BeginCreateSecurityTokenRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.BeginSelectCardRequest:
                        uiAgentRequest = (UIAgentRequest)new BeginSelectCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.CancelAsyncOperationRequest:
                        uiAgentRequest = (UIAgentRequest)new CancelAsyncOperationRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.CreateCardRequest:
                        uiAgentRequest = (UIAgentRequest)new CreateCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.CheckStoreFileValidityRequest:
                        uiAgentRequest = (UIAgentRequest)new CheckStoreFileValidityRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.DeleteCardRequest:
                        uiAgentRequest = (UIAgentRequest)new DeleteCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.DeleteStoreRequest:
                        uiAgentRequest = (UIAgentRequest)new DeleteStoreRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.EndCreateSecurityTokenRequest:
                        uiAgentRequest = (UIAgentRequest)new EndCreateSecurityTokenRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.EndSelectCardRequest:
                        uiAgentRequest = (UIAgentRequest)new EndSelectCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.ExportFileRequest:
                        uiAgentRequest = (UIAgentRequest)new ExportFileRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetCertificateRequest:
                        uiAgentRequest = (UIAgentRequest)new GetCertificateRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetImportedCardRequest:
                        uiAgentRequest = (UIAgentRequest)new GetImportedCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetImportFileNameRequest:
                        uiAgentRequest = (UIAgentRequest)new GetImportFileNameRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetLedgerEntryForRecipientRequest:
                        uiAgentRequest = (UIAgentRequest)new GetLedgerEntryForRecipientRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetLedgerRequest:
                        uiAgentRequest = (UIAgentRequest)new GetLedgerRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetPolicyDetailsRequest:
                        uiAgentRequest = (UIAgentRequest)new GetPolicyDetailsRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetRecipientListRequest:
                        uiAgentRequest = (UIAgentRequest)new GetRecipientListRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetRecipientRequest:
                        uiAgentRequest = (UIAgentRequest)new GetRecipientRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetUserPreferenceRequest:
                        uiAgentRequest = (UIAgentRequest)new GetUserPreferenceRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.ImportFileRequest:
                        uiAgentRequest = (UIAgentRequest)new ImportFileRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.InfoCardListRequest:
                        uiAgentRequest = (UIAgentRequest)new InfoCardListRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.ListCardsInFileRequest:
                        uiAgentRequest = (UIAgentRequest)new ListCardsInFileRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.QueryStoreStatusRequest:
                        uiAgentRequest = (UIAgentRequest)new QueryStoreStatusRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.ResolvePPIDRequest:
                        uiAgentRequest = (UIAgentRequest)new ResolvePPIDRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.SaveCardRequest:
                        uiAgentRequest = (UIAgentRequest)new SaveCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.SaveLedgerEntryRequest:
                        uiAgentRequest = (UIAgentRequest)new SaveLedgerEntryRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.SaveRecipientRequest:
                        uiAgentRequest = (UIAgentRequest)new SaveRecipientRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.SendAgentStatusRequest:
                        uiAgentRequest = (UIAgentRequest)new SendAgentStatusRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.SetUserPreferenceRequest:
                        uiAgentRequest = (UIAgentRequest)new SetUserPreferenceRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.UIEndRequest:
                        uiAgentRequest = (UIAgentRequest)new UIEndRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.BeginGetFileNameFromUserRequest:
                        uiAgentRequest = (UIAgentRequest)new BeginGetFileNameFromUserRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.EndGetFileNameFromUserRequest:
                        uiAgentRequest = (UIAgentRequest)new EndGetFileNameFromUserRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.ListDependantCardsRequest:
                        uiAgentRequest = (UIAgentRequest)new ListDependantCardsRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetLastErrorDetailsRequest:
                        uiAgentRequest = (UIAgentRequest)new GetLastErrorDetailsRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetIsBrowserClientRequest:
                        uiAgentRequest = (UIAgentRequest)new GetIsBrowserClientRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.SetUserLanguageRequest:
                        uiAgentRequest = (UIAgentRequest)new SetUserLanguageRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.GetCardDetailsRequest:
                        uiAgentRequest = (UIAgentRequest)new GetCardDetailsRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    case RequestFactory.RequestName.UnlockCardRequest:
                        uiAgentRequest = (UIAgentRequest)new UnlockCardRequest(rpcHandle, inStream, outStream, parentRequest);
                        break;
                    default:
                        throw InfoCardTrace.ThrowHelperError((Exception)new CommunicationException());
                }
                uiAgentRequest.Initialize();
            }
            return uiAgentRequest;
        }

        private enum RequestName
        {
            CloseCryptoHandleRequest = 0,
            DecryptRequest = 1,
            EncryptRequest = 2,
            GenerateDerivedKeyRequest = 3,
            GetBrowserTokenRequest = 4,
            GetCryptoTransformRequest = 5,
            GetKeyedHashRequest = 6,
            GetTokenRequest = 7,
            HashCoreRequest = 8,
            HashFinalRequest = 9,
            ImportRequest = 10, // 0x0000000A
            ManageRequest = 11, // 0x0000000B
            SignHashRequest = 12, // 0x0000000C
            TransformBlockRequest = 13, // 0x0000000D
            TransformFinalBlockRequest = 14, // 0x0000000E
            VerifyHashRequest = 15, // 0x0000000F
            ClientRequestCount = 16, // 0x00000010
            AgentRequestCount = 38, // 0x00000026
            BeginCreateSecurityTokenRequest = 128, // 0x00000080
            BeginSelectCardRequest = 129, // 0x00000081
            CancelAsyncOperationRequest = 130, // 0x00000082
            CreateCardRequest = 131, // 0x00000083
            CheckStoreFileValidityRequest = 132, // 0x00000084
            DeleteCardRequest = 133, // 0x00000085
            DeleteStoreRequest = 134, // 0x00000086
            EndCreateSecurityTokenRequest = 135, // 0x00000087
            EndSelectCardRequest = 136, // 0x00000088
            ExportFileRequest = 137, // 0x00000089
            GetCertificateRequest = 138, // 0x0000008A
            GetImportedCardRequest = 139, // 0x0000008B
            GetImportFileNameRequest = 140, // 0x0000008C
            GetLedgerEntryForRecipientRequest = 141, // 0x0000008D
            GetLedgerRequest = 142, // 0x0000008E
            GetPolicyDetailsRequest = 143, // 0x0000008F
            GetRecipientListRequest = 144, // 0x00000090
            GetRecipientRequest = 145, // 0x00000091
            GetUserPreferenceRequest = 146, // 0x00000092
            ImportFileRequest = 147, // 0x00000093
            InfoCardListRequest = 148, // 0x00000094
            ListCardsInFileRequest = 149, // 0x00000095
            QueryStoreStatusRequest = 150, // 0x00000096
            ResolvePPIDRequest = 151, // 0x00000097
            SaveCardRequest = 152, // 0x00000098
            SaveLedgerEntryRequest = 153, // 0x00000099
            SaveRecipientRequest = 154, // 0x0000009A
            SendAgentStatusRequest = 155, // 0x0000009B
            SetUserPreferenceRequest = 156, // 0x0000009C
            UIEndRequest = 157, // 0x0000009D
            BeginGetFileNameFromUserRequest = 158, // 0x0000009E
            EndGetFileNameFromUserRequest = 159, // 0x0000009F
            ListDependantCardsRequest = 160, // 0x000000A0
            GetLastErrorDetailsRequest = 161, // 0x000000A1
            GetIsBrowserClientRequest = 162, // 0x000000A2
            SetUserLanguageRequest = 163, // 0x000000A3
            GetCardDetailsRequest = 164, // 0x000000A4
            UnlockCardRequest = 165, // 0x000000A5
        }
    }
}
